from django.shortcuts import render
from django.http import JsonResponse,HttpResponse
from django.db import connection
import  time
from .lib import redisPool
import json

# 链接数据库对象

def  redistest(request):
    if redisPool.pool.set('name',111) :
        return  HttpResponse('Ok')
    else:
        return HttpResponse('NO')





























# Create your views here.
def test(request):
    return HttpResponse('is ok')



def getauth(request) -> "获取用户列表":

    account = request.POST.get('account')
    token  = request.POST.get('token')
    print(account)
    if  account == None or token == None or token != str(123) :
        return JsonResponse({'message':'参数错误！请检查后调用！'})
    try:
        with connection.cursor() as cursor:
            cursor.execute("select * from y_account where account= '%s'"%(account))
            raw = cursor.fetchall()
            # print(raw)
    except Exception as e :
        return HttpResponse( str(e))

    auth_data = {
        ''
        'ID':raw[0][0],
        'account':raw[0][1],
        'account_name':raw[0][2],
        'role_id':raw[0][3],
        'sex':raw[0][4],
        'age':raw[0][5],
        'wechat_num':raw[0][6],
        'mobile_num':raw[0][7],
        'status':raw[0][8],
        'CREATED_BY':raw[0][9],
        'CREATED_TIME':raw[0][10],
        'UPDATED_BY':raw[0][11],
        'UPDATED_TIME':raw[0][12],
        'del_status':raw[0][13],
    }

    # auth_data = json.dumps(auth_data)
    dates =  time.strftime('%Y-%m-%d %H:%M:%S')
    return JsonResponse(auth_data )


def LoginCheck(request) -> '登陆密码校验':
    account = request.POST.get('account')
    pasword  = request.POST.get('pasword')


    #  redis 获取到密码
    if  pasword == 'test':

        return 1
    else:
        return render({'a':123})


